package com.yoga.admin.api.web;

import com.yoga.admin.api.annotation.LoginUser;
import com.yoga.common.appexception.AppException;
import com.yoga.common.appexception.YogaResult;
import com.yoga.common.bo.ClassTableBO;
import com.yoga.common.bo.YogaAdminBO;
import com.yoga.common.page.PageBO;
import com.yoga.common.qto.ClassTableQTO;
import com.yoga.manager.admin.AdminClassTableManager;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by hdx on 2020/10/17.
 */
@RestController
@RequestMapping("${basePath}")
public class AdminClassTableController {

    @Resource
    private AdminClassTableManager classTableManager;

    @PostMapping("/classTable/add")
    public YogaResult<ClassTableBO> addData(@LoginUser YogaAdminBO adminBO, @RequestBody ClassTableBO classTableBO) throws AppException {
        ClassTableBO result = classTableManager.addData(classTableBO);

        return new YogaResult<>(result);
    }

    @PostMapping("/classTable/update")
    public YogaResult<Boolean> updateData(@LoginUser YogaAdminBO adminBO, @RequestBody ClassTableBO classTableBO) throws AppException {
        Boolean result = classTableManager.updateData(classTableBO);

        return new YogaResult<>(result);
    }

    @PostMapping("/classTable/delete")
    public YogaResult<Boolean> deleteData(@LoginUser YogaAdminBO adminBO, Long classTableId) throws AppException {
        Boolean result = classTableManager.deleteData(classTableId);

        return new YogaResult<>(result);
    }

    @PostMapping("/classTable/findDay")
    public YogaResult<PageBO<ClassTableBO>> findDay(@LoginUser YogaAdminBO adminBO, ClassTableQTO classTableQTO) throws AppException {
        PageBO<ClassTableBO> result = classTableManager.findForPage(classTableQTO);

        return new YogaResult<>(result);
    }

    @PostMapping("/classTable/findWeek")
    public YogaResult<PageBO<Map<Date, List<ClassTableBO>>>> findWeek(@LoginUser YogaAdminBO adminBO, ClassTableQTO classTableQTO) throws AppException {
        PageBO<Map<Date, List<ClassTableBO>>> result = classTableManager.findForPageWeekGroup(classTableQTO);

        return new YogaResult<>(result);
    }

    /**
     * 拷贝上周到课表到本周
     * @param adminBO
     * @param yogaShopId
     * @return
     * @throws AppException
     */
    @PostMapping("/classTable/copyUpWeek")
    public YogaResult<Boolean> copyUpWeekClassTable(@LoginUser YogaAdminBO adminBO, Long yogaShopId) throws AppException {
        Boolean result = classTableManager.copyUpWeekClassTable(yogaShopId);

        return new YogaResult<>(result);
    }

    /**
     * 将本周课表拷贝至下周
     * @param adminBO
     * @param yogaShopId
     * @return
     * @throws AppException
     */
    @PostMapping("/classTable/copyToNextWeek")
    public YogaResult<Boolean> copy2NextWeek(@LoginUser YogaAdminBO adminBO, Long yogaShopId) throws AppException {
        Boolean result = classTableManager.copy2NextWeek(yogaShopId);

        return new YogaResult<>(result);
    }





}
